//
// Created by 25313 on 2025/8/5.
//
class Solution {
public:
    long long pickGifts(vector<int>& gifts, int k) {
        long long res = 0;
        priority_queue<int> max_queue(gifts.begin(),gifts.end());
        for(int i = 0; i < k; i++)
        {
            int x = max_queue.top();
            x = sqrt(x);
            max_queue.pop();
            max_queue.push(x);
        }
        while(!max_queue.empty())
        {
            int y = max_queue.top();
            max_queue.pop();
            res += y;
        }
        return res;
    }
};